uniform sampler2D theTexture;
uniform sampler2D normalMap;

// computed in vertex shader
varying vec3 N, L;

void main() {
	// get the texture colour
	vec3 textureColour = vec3(texture2D(theTexture, gl_TexCoord[0].st));
	gl_FragColor = vec4(textureColour, 1.0);
	
	vec3	normalMapValue = normalize(vec3(texture2D(normalMap, gl_TexCoord[0].st)));
	
	// work out intensity as function of interpolated normal N and light vector L
	// using standard diffuse lighting equation
	float diffuseIntensity = max(0.0, dot(normalize(N) * normalMapValue, normalize(L)));
	
	// factor in diffuseIntensity
	gl_FragColor.rgb *= diffuseIntensity;
	
}
